package com.lg.spring.kafka.producer;

import com.google.gson.Gson;
import com.lg.spring.kafka.KafkaMessage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.stereotype.Component;

/**
 * Kafka 的生产者
 *
 * @author by Mr. Li 2020/9/15 12:30
 */
//@Component
public class KafkaProducer {
	@Autowired
	private KafkaTemplate<String, String> kafkaTemplate;

	public void sendKafkaMessage(KafkaMessage kafkaMessage) {
		this.kafkaTemplate.send("myTopic", new Gson().toJson(kafkaMessage));
	}
}
